﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoDbObject;
using SZJT.Utility.DataSource;

namespace Colligate.DataSource.DriverTraining.Business.Student
{
    class BusinessStudentInfo : BaseLegoModule
    {
        private const string TABLE_STUDENT_INFO = "BusinessStudentInfo";

        public BusinessStudentInfo(IDataSourceLayer dataLayer)
            : base(new string[] { TABLE_STUDENT_INFO }, dataLayer)
        {
        }

        #region 返回Lego模块涉及到的数据名称的结构信息
        /// <summary>
        /// 返回Lego模块涉及到的数据名称的结构信息
        /// </summary>
        /// <param name="strDataName">基础表名称</param>
        /// <returns>表结构信息</returns>
        override public IFieldInfo[] GetStructInfo(string strDataName)
        {
            // 建立IFieldInfo列表
            // CFieldInfo(字段名, 类型, 长度, 索引, 状态, 字段说明, 字段帮助, 显示的格式化字符串, 字段宽度, 关联记录)
            // 类型： text，byte，short，long，single，double，currency，date，logical，memo，binary
            // 索引： 0 无索引，1 重复索引，2 唯一索引，3 关键字段
            // 状态： 0 系统字段，>1显示信息的字段， 2 用于标识记录名称的字段

            IFieldInfo[] tableStructInfo;
            switch (strDataName)
            {
                case TABLE_STUDENT_INFO:	 // 学员信息
                    tableStructInfo = new IFieldInfo[16];
                    tableStructInfo[0] = new CFieldInfo("fStudentGuid", "text", 36, 2, 0, "学员信息", "学员信息", "", 52, 0);
                    tableStructInfo[1] = new CFieldInfo("fStudentName", "text", 10, 0, 1, "学员姓名", "学员姓名", "", 52, 0);
                    tableStructInfo[2] = new CFieldInfo("fStudentSex", "text", 2, 0, 1, "学员性别[女|男]", "学员性别[女|男]", "", 52, 0);
                    tableStructInfo[3] = new CFieldInfo("fStudentType", "text", 20, 0, 1, "学员证件类型[身份证|军官证|护照]", "学员证件类型[身份证|军官证|护照]", "", 52, 0);
                    tableStructInfo[4] = new CFieldInfo("fStudentID", "text", 30, 0, 1, "学员证件号", "学员证件号", "", 52, 0);
                    tableStructInfo[5] = new CFieldInfo("fStudentAge", "long", 0, 0, 1, "学员年龄", "学员年龄", "", 52, 0);
                    tableStructInfo[6] = new CFieldInfo("fStudentCode", "text", 20, 0, 1, "学员号", "学员号", "", 52, 0);
                    tableStructInfo[7] = new CFieldInfo("fStudentMobile", "text", 20, 0, 1, "学员手机号", "学员手机号", "", 52, 0);
                    tableStructInfo[8] = new CFieldInfo("fStudentMail", "text", 100, 0, 1, "学员邮箱", "学员邮箱", "", 52, 0);
                    tableStructInfo[9] = new CFieldInfo("fStudentAccount", "text", 20, 0, 1, "学员帐号", "学员帐号", "", 52, 0);
                    tableStructInfo[10] = new CFieldInfo("fStudentPassword", "text", 20, 0, 1, "学员密码", "学员密码", "", 52, 0);
                    tableStructInfo[11] = new CFieldInfo("fStudentStatus", "text", 10, 0, 1, "学员状态[在学|已毕业|已退学]", "学员状态[在学|已毕业|已退学]", "", 52, 0);
                    tableStructInfo[12] = new CFieldInfo("fSchoolGuid", "text", 36, 0, 1, "驾校标识", "驾校标识", "", 52, 0);
                    tableStructInfo[13] = new CFieldInfo("fSchoolName", "text", 50, 0, 1, "驾校名称", "驾校名称", "", 52, 0);
                    tableStructInfo[14] = new CFieldInfo("fFingerprinter1", "memo", 0, 0, 1, "指纹特征码1", "指纹特征码1", "", 52, 0);
                    tableStructInfo[15] = new CFieldInfo("fFingerprinter2", "memo", 0, 0, 1, "指纹特征码2", "指纹特征码2", "", 52, 0);
                    break;
                default: tableStructInfo = null; break;
            }
            return tableStructInfo;
        }
        #endregion

        #region 学员信息
        public IDBDataObject GetStudentInfoData(string studentGUID)
        {
            string tableName = GetStructGlobalName(TABLE_STUDENT_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fStudentGuid = '{0}'", studentGUID));
        }

        public IDBBigObjectSet GetLastStudentInfoData()
        {
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_STUDENT_INFO), "", "fStudentID asc");
        }

        public IDBDataObject GetStudentById(string studentID)
        {
            return DataLayer.GetDBDataObject(GetStructGlobalName(TABLE_STUDENT_INFO), string.Format("fStudentID = '{0}'", studentID));
        }

        public IDBBigObjectSet GetStudentList(string studentName, string studentSex, string studentID, string studentMobile, string studentStatus)
        {
            QueryFilter queryFilter = new QueryFilter();
            queryFilter.AddFilter("fStudentName", studentName, "{0} like '%{1}%'");
            queryFilter.AddFilter("fStudentSex", QueryFilter.FilterType.TEXT, studentSex);
            queryFilter.AddFilter("fStudentID", studentID, "{0} like '%{1}%'");
            queryFilter.AddFilter("fStudentMobile", studentMobile, "{0} like '%{1}%'");
            queryFilter.AddFilter("fStudentStatus", QueryFilter.FilterType.TEXT, studentStatus);
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_STUDENT_INFO), queryFilter.FilterString, "fStudentName");
        }

        public IDBDataObject GetStudentInfoByFingerprinter(string fingerprinter)
        {
            string tableName = GetStructGlobalName(TABLE_STUDENT_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fFingerprinter1 = '{0}' or fFingerprinter2 = '{0}'", fingerprinter));
        }
        #endregion

    }
}
